<!-- HTML header for doxygen 1.8.9.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>ROSS: core/buddy.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <a href="https://github.com/ROSS-org/ROSS">
   <div id="projectname">ROSS
   </div>
   </a>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_af18cf245e3394ab3b436135935cfd6e.html">core</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">buddy.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="buddy_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef BUDDY_H</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#define BUDDY_H</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;sys/queue.h&gt;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * @file buddy.h</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> * @brief Buddy-system memory allocator</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div>
<div class="line"><a name="l00011"></a><span class="lineno"><a class="line" href="buddy_8h.html#ae2694cc0545e0b4d3fc4a32ab1b33ce9a1e780c62cb3fd2edcac39f739bbe6f6c">   11</a></span>&#160;<span class="keyword">typedef</span> <span class="keyword">enum</span> <a class="code" href="buddy_8h.html#ae2694cc0545e0b4d3fc4a32ab1b33ce9">purpose</a> { <a class="code" href="buddy_8h.html#ae2694cc0545e0b4d3fc4a32ab1b33ce9acc62d1576546f3245237e1b232d838b6">FREE</a>, <a class="code" href="buddy_8h.html#ae2694cc0545e0b4d3fc4a32ab1b33ce9a1e780c62cb3fd2edcac39f739bbe6f6c">USED</a> } <a class="code" href="buddy_8h.html#a21e0915fcd423dccf0a145edec34ebe8">purpose_t</a>;</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;</div>
<div class="line"><a name="l00013"></a><span class="lineno"><a class="line" href="buddy_8h.html#adcd960f6050174cbf799e5bca60aea48">   13</a></span>&#160;<span class="preprocessor">#define BUDDY_ALIGN_PREF (32 - 2 * sizeof(void*) - sizeof(uint32_t) - sizeof(purpose_t))</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor"></span><span class="comment"></span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> * Metadata about this particular block</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> * (and stored at the beginning of this block).</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> * One per allocated block of memory.</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> * Should be 32 bytes to not screw up alignment.</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00021"></a><span class="lineno"><a class="line" href="structbuddy__list.html">   21</a></span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structbuddy__list.html">buddy_list</a></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;{</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;    <span class="comment">// Should be two pointers</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;    <a class="code" href="structbuddy__list.html#a469a570619c3e52b76d23180121b0db4">LIST_ENTRY</a>(<a class="code" href="structbuddy__list.html">buddy_list</a>) next_freelist;</div>
<div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="structbuddy__list.html#a8f5f5a95250726834f37a5068dc1c8b4">   25</a></span>&#160;    uint32_t <a class="code" href="structbuddy__list.html#a8f5f5a95250726834f37a5068dc1c8b4">size</a>;</div>
<div class="line"><a name="l00026"></a><span class="lineno"><a class="line" href="structbuddy__list.html#a5a2f3daf9d6704b4a70df1bf2bcea8db">   26</a></span>&#160;    <a class="code" href="buddy_8h.html#a21e0915fcd423dccf0a145edec34ebe8">purpose_t</a> <a class="code" href="structbuddy__list.html#a5a2f3daf9d6704b4a70df1bf2bcea8db">use</a>;</div>
<div class="line"><a name="l00027"></a><span class="lineno"><a class="line" href="structbuddy__list.html#a6a90292a6207a7a964c19df17eab0d80">   27</a></span>&#160;    <span class="keywordtype">char</span> <a class="code" href="structbuddy__list.html#a6a90292a6207a7a964c19df17eab0d80">padding</a>[<a class="code" href="buddy_8h.html#adcd960f6050174cbf799e5bca60aea48">BUDDY_ALIGN_PREF</a>];</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;} <a class="code" href="buddy_8h.html#aa75928b4c911a0d613473267a0585d6d">buddy_list_t</a>;</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;</div>
<div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="buddy_8h.html#a51646327ac0a3287c4b08e4d28b66f35">   30</a></span>&#160;<span class="keyword">typedef</span> <span class="keyword">enum</span> <a class="code" href="buddy_8h.html#a51646327ac0a3287c4b08e4d28b66f35">valid</a> { <a class="code" href="buddy_8h.html#a51646327ac0a3287c4b08e4d28b66f35acf0713491d9b887eaccfd80c18abca47">VALID</a>, <a class="code" href="buddy_8h.html#a51646327ac0a3287c4b08e4d28b66f35aef2863a469df3ea6871d640e3669a2f2">INVALID</a> } <a class="code" href="buddy_8h.html#aaa7362f730dd0743731a2b0b0082fb88">valid_t</a>;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="comment"> * Bucket of 2^order sized free memory blocks.</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="structbuddy__list__bucket.html">   35</a></span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structbuddy__list__bucket.html">buddy_list_bucket</a></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;{</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    <a class="code" href="structbuddy__list__bucket.html#a93069ab581eea8666644efeeb6db213c">LIST_HEAD</a>(buddy_list_head, <a class="code" href="structbuddy__list.html">buddy_list</a>) ptr;</div>
<div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="structbuddy__list__bucket.html#a0419513cdd8f0622e11a40ef5b00cbcd">   38</a></span>&#160;    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structbuddy__list__bucket.html#a0419513cdd8f0622e11a40ef5b00cbcd">count</a>;</div>
<div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="structbuddy__list__bucket.html#a4fef6b7e7203a58718f141e97a5480c8">   39</a></span>&#160;    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structbuddy__list__bucket.html#a4fef6b7e7203a58718f141e97a5480c8">order</a>;</div>
<div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="structbuddy__list__bucket.html#a2e26ecbfd58890521d5f74aea4f570e6">   40</a></span>&#160;    <a class="code" href="buddy_8h.html#aaa7362f730dd0743731a2b0b0082fb88">valid_t</a> <a class="code" href="structbuddy__list__bucket.html#a2e26ecbfd58890521d5f74aea4f570e6">is_valid</a>;</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;} <a class="code" href="buddy_8h.html#a676bc3bde2d2bce99f474f3e0b20700d">buddy_list_bucket_t</a>;</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;<a class="code" href="structbuddy__list__bucket.html">buddy_list_bucket_t</a> * <a class="code" href="buddy_8h.html#ac7158d51ffbe54dd3e04d6568f90c42c">create_buddy_table</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> power_of_two);</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="keywordtype">void</span> *<a class="code" href="buddy_8h.html#aa9dd0e2ab55c7090670a556e026f515c">buddy_alloc</a>(<span class="keywordtype">unsigned</span> size);</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="keywordtype">void</span> <a class="code" href="buddy_8h.html#a2d38d5280dce5d4f0b85410e00c293a6">buddy_free</a>(<span class="keywordtype">void</span> *ptr);</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* BUDDY_H */</span><span class="preprocessor"></span></div>
<div class="ttc" id="structbuddy__list_html_a8f5f5a95250726834f37a5068dc1c8b4"><div class="ttname"><a href="structbuddy__list.html#a8f5f5a95250726834f37a5068dc1c8b4">buddy_list::size</a></div><div class="ttdeci">uint32_t size</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00025">buddy.h:25</a></div></div>
<div class="ttc" id="buddy_8h_html_aa75928b4c911a0d613473267a0585d6d"><div class="ttname"><a href="buddy_8h.html#aa75928b4c911a0d613473267a0585d6d">buddy_list_t</a></div><div class="ttdeci">struct buddy_list buddy_list_t</div></div>
<div class="ttc" id="buddy_8h_html_adcd960f6050174cbf799e5bca60aea48"><div class="ttname"><a href="buddy_8h.html#adcd960f6050174cbf799e5bca60aea48">BUDDY_ALIGN_PREF</a></div><div class="ttdeci">#define BUDDY_ALIGN_PREF</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00013">buddy.h:13</a></div></div>
<div class="ttc" id="structbuddy__list__bucket_html_a0419513cdd8f0622e11a40ef5b00cbcd"><div class="ttname"><a href="structbuddy__list__bucket.html#a0419513cdd8f0622e11a40ef5b00cbcd">buddy_list_bucket::count</a></div><div class="ttdeci">unsigned int count</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00038">buddy.h:38</a></div></div>
<div class="ttc" id="buddy_8h_html_ac7158d51ffbe54dd3e04d6568f90c42c"><div class="ttname"><a href="buddy_8h.html#ac7158d51ffbe54dd3e04d6568f90c42c">create_buddy_table</a></div><div class="ttdeci">buddy_list_bucket_t * create_buddy_table(unsigned int power_of_two)</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8c_source.html#l00288">buddy.c:288</a></div></div>
<div class="ttc" id="buddy_8h_html_ae2694cc0545e0b4d3fc4a32ab1b33ce9a1e780c62cb3fd2edcac39f739bbe6f6c"><div class="ttname"><a href="buddy_8h.html#ae2694cc0545e0b4d3fc4a32ab1b33ce9a1e780c62cb3fd2edcac39f739bbe6f6c">USED</a></div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00011">buddy.h:11</a></div></div>
<div class="ttc" id="structbuddy__list_html"><div class="ttname"><a href="structbuddy__list.html">buddy_list</a></div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00021">buddy.h:21</a></div></div>
<div class="ttc" id="buddy_8h_html_a2d38d5280dce5d4f0b85410e00c293a6"><div class="ttname"><a href="buddy_8h.html#a2d38d5280dce5d4f0b85410e00c293a6">buddy_free</a></div><div class="ttdeci">void buddy_free(void *ptr)</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8c_source.html#l00137">buddy.c:137</a></div></div>
<div class="ttc" id="buddy_8h_html_a676bc3bde2d2bce99f474f3e0b20700d"><div class="ttname"><a href="buddy_8h.html#a676bc3bde2d2bce99f474f3e0b20700d">buddy_list_bucket_t</a></div><div class="ttdeci">struct buddy_list_bucket buddy_list_bucket_t</div></div>
<div class="ttc" id="buddy_8h_html_a51646327ac0a3287c4b08e4d28b66f35aef2863a469df3ea6871d640e3669a2f2"><div class="ttname"><a href="buddy_8h.html#a51646327ac0a3287c4b08e4d28b66f35aef2863a469df3ea6871d640e3669a2f2">INVALID</a></div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00030">buddy.h:30</a></div></div>
<div class="ttc" id="structbuddy__list__bucket_html_a2e26ecbfd58890521d5f74aea4f570e6"><div class="ttname"><a href="structbuddy__list__bucket.html#a2e26ecbfd58890521d5f74aea4f570e6">buddy_list_bucket::is_valid</a></div><div class="ttdeci">valid_t is_valid</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00040">buddy.h:40</a></div></div>
<div class="ttc" id="buddy_8h_html_ae2694cc0545e0b4d3fc4a32ab1b33ce9acc62d1576546f3245237e1b232d838b6"><div class="ttname"><a href="buddy_8h.html#ae2694cc0545e0b4d3fc4a32ab1b33ce9acc62d1576546f3245237e1b232d838b6">FREE</a></div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00011">buddy.h:11</a></div></div>
<div class="ttc" id="structbuddy__list__bucket_html"><div class="ttname"><a href="structbuddy__list__bucket.html">buddy_list_bucket</a></div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00035">buddy.h:35</a></div></div>
<div class="ttc" id="buddy_8h_html_a51646327ac0a3287c4b08e4d28b66f35acf0713491d9b887eaccfd80c18abca47"><div class="ttname"><a href="buddy_8h.html#a51646327ac0a3287c4b08e4d28b66f35acf0713491d9b887eaccfd80c18abca47">VALID</a></div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00030">buddy.h:30</a></div></div>
<div class="ttc" id="buddy_8h_html_aa9dd0e2ab55c7090670a556e026f515c"><div class="ttname"><a href="buddy_8h.html#aa9dd0e2ab55c7090670a556e026f515c">buddy_alloc</a></div><div class="ttdeci">void * buddy_alloc(unsigned size)</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8c_source.html#l00234">buddy.c:234</a></div></div>
<div class="ttc" id="buddy_8h_html_a51646327ac0a3287c4b08e4d28b66f35"><div class="ttname"><a href="buddy_8h.html#a51646327ac0a3287c4b08e4d28b66f35">valid</a></div><div class="ttdeci">valid</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00030">buddy.h:30</a></div></div>
<div class="ttc" id="structbuddy__list__bucket_html_a4fef6b7e7203a58718f141e97a5480c8"><div class="ttname"><a href="structbuddy__list__bucket.html#a4fef6b7e7203a58718f141e97a5480c8">buddy_list_bucket::order</a></div><div class="ttdeci">unsigned int order</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00039">buddy.h:39</a></div></div>
<div class="ttc" id="buddy_8h_html_aaa7362f730dd0743731a2b0b0082fb88"><div class="ttname"><a href="buddy_8h.html#aaa7362f730dd0743731a2b0b0082fb88">valid_t</a></div><div class="ttdeci">enum valid valid_t</div></div>
<div class="ttc" id="buddy_8h_html_ae2694cc0545e0b4d3fc4a32ab1b33ce9"><div class="ttname"><a href="buddy_8h.html#ae2694cc0545e0b4d3fc4a32ab1b33ce9">purpose</a></div><div class="ttdeci">purpose</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00011">buddy.h:11</a></div></div>
<div class="ttc" id="structbuddy__list_html_a469a570619c3e52b76d23180121b0db4"><div class="ttname"><a href="structbuddy__list.html#a469a570619c3e52b76d23180121b0db4">buddy_list::LIST_ENTRY</a></div><div class="ttdeci">LIST_ENTRY(buddy_list) next_freelist</div></div>
<div class="ttc" id="structbuddy__list__bucket_html_a93069ab581eea8666644efeeb6db213c"><div class="ttname"><a href="structbuddy__list__bucket.html#a93069ab581eea8666644efeeb6db213c">buddy_list_bucket::LIST_HEAD</a></div><div class="ttdeci">LIST_HEAD(buddy_list_head, buddy_list) ptr</div></div>
<div class="ttc" id="structbuddy__list_html_a5a2f3daf9d6704b4a70df1bf2bcea8db"><div class="ttname"><a href="structbuddy__list.html#a5a2f3daf9d6704b4a70df1bf2bcea8db">buddy_list::use</a></div><div class="ttdeci">purpose_t use</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00026">buddy.h:26</a></div></div>
<div class="ttc" id="buddy_8h_html_a21e0915fcd423dccf0a145edec34ebe8"><div class="ttname"><a href="buddy_8h.html#a21e0915fcd423dccf0a145edec34ebe8">purpose_t</a></div><div class="ttdeci">enum purpose purpose_t</div></div>
<div class="ttc" id="structbuddy__list_html_a6a90292a6207a7a964c19df17eab0d80"><div class="ttname"><a href="structbuddy__list.html#a6a90292a6207a7a964c19df17eab0d80">buddy_list::padding</a></div><div class="ttdeci">char padding[(32-2 *sizeof(void *)-sizeof(uint32_t)-sizeof(purpose_t))]</div><div class="ttdef"><b>Definition:</b> <a href="buddy_8h_source.html#l00027">buddy.h:27</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>
